package com.qs.eggs.base.activity;

import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.qs.eggs.R;

public abstract class BackActivity extends BaseActivity {
    private LinearLayout root_layout;
    private View toolbar_layout;

    private TextView tv_left_back;
    private TextView tv_title;

    @Override
    public boolean onSupportNavigateUp() {
        finish();
        return super.onSupportNavigateUp();
    }



    /**
     * 初始化 toolbar 内容布局
     */
    private void initToolbar() {
        tv_left_back = f(R.id.tv_back);
        tv_title = f(R.id.tv_title);
      //  toolbar_layout = f(R.id.ll_toolbar);
    }

    /**
     * 设置返回按钮
     */
    protected void setBack() {
        if (tv_left_back != null) {
            tv_left_back.setVisibility(View.VISIBLE);
            tv_left_back.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
        }
    }

    /**
     * 设置当前 Activity 标题
     *
     * @param title
     */
    protected void setTitle(String title) {
        if (tv_title != null) {
            tv_title.setVisibility(View.VISIBLE);
            tv_title.setText(title);
        }
    }

    /**
     * 隐藏头部标题栏
     */
    protected void hideToolbar() {
        if (toolbar_layout != null) {
            toolbar_layout.setVisibility(View.GONE);
        }
    }

    protected <T extends View> T f(int id) {
        return (T) findViewById(id);
    }
}
